/**
 * @Description:
 * @Author: CHEHSHUANG
 * @Date: 2019/3/14
 */
import React, {Component} from 'react';
import {Form, Input} from "antd";
import StandardModal from "../../../commons/components/StandardModal";

const FormItem = Form.Item;

class PasswordEditModal extends Component {
  componentDidMount() {
    this.props.onRef && this.props.onRef(this);
  }

  getFormValue = () => {
    let result = false;
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        result = values;
      }
    });
    return result;
  }

  render() {
    const formItemLayout = {
      labelCol: {
        span: 8
      },
      wrapperCol: {
        span: 12
      },
    };

    const {parentData, confirmLoading, visible, onCancel, onOk, editData, flag} = this.props;
    const {getFieldDecorator} = this.props.form;
    let initValue = editData;
    console.log(editData);
    return (
      <StandardModal
        title={"修改密码"}
        visible={visible}
        onOk={onOk}
        onCancel={onCancel}
        width={600}
        confirmLoading={confirmLoading}
        maskClosable={false}
      >
        <Form>
          <FormItem
            style={{display: "none"}}
          >
            {getFieldDecorator('userAccountId', {
              initialValue: initValue && initValue.id ? initValue.id : "",
            })(
              <Input disabled={true}/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="账号">
            {getFieldDecorator('account', {
              initialValue: initValue && initValue.account ? initValue.account : "",
            })(
              <Input disabled/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="旧密码">
            {getFieldDecorator('oldPassword', {
              initialValue: "",
              rules: [{required: true, message: '请填写旧密码!'}]
            })(
              <Input.Password visibilityToggle={true}/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="新密码">
            {getFieldDecorator('newPassword', {
              initialValue: "",
              rules: [{required: true, message: '请填写新密码!'}]
            })(
              <Input.Password visibilityToggle={true}/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="确认新密码">
            {getFieldDecorator('confirmNewPassword', {
              initialValue: "",
              rules: [{required: true, message: '请填写确认新密码!'}]
            })(
              <Input.Password visibilityToggle={true}/>
            )}
          </FormItem>
        </Form>
      </StandardModal>
    );
  }
}

export default Form.create()(PasswordEditModal);
